Platform Explorer / Nuxeo Platform 2021.54

Component org.nuxeo.platform.TemplateSources.operations

Documentation

Contribute Operation to encapsulate TemplateProcessor rendering features

Resolution Order

884
The resolution order represents the order in which this component has been resolved by the Nuxeo Runtime framework.
You can influence this order by adding "require" tags in your component declaration, to make sure it is resolved after another component.

Contributions

XML Source

<?xml version="1.0"?>
<component name="org.nuxeo.platform.TemplateSources.operations" version="1.0">

  <documentation>
  Contribute Operation to encapsulate TemplateProcessor rendering features
  @author Tiry (tdelprat@nuxeo.com)</documentation>

  <extension target="org.nuxeo.ecm.core.operation.OperationServiceComponent"
    point="operations">

    <operation
      class="org.nuxeo.template.automation.RenderWithTemplateOperation" />
    <operation
      class="org.nuxeo.template.automation.DetachTemplateOperation" />

  </extension>

  <extension target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent" point="operation">

    <scriptedOperation id="javascript.FilterTemplatesByType">
      <inputType>document</inputType>
      <outputType>documents</outputType>
      <category>javascript</category>
      <description>Filter templates according to the type of a given input document.</description>
      <script><![CDATA[
        function run(input, params) {
          return Repository.Query(null, {
            'query': 'select * from Document where ecm:mixinType = "Template" AND ecm:isTrashed = 0 AND tmpl:applicableTypes IN ( "all", "' + input['type'] + '") AND ecm:isVersion = 0'
          });
        }
      ]]></script>
    </scriptedOperation>

    <scriptedOperation id="javascript.RenderPdf">
      <inputType>document</inputType>
      <outputType>blob</outputType>
      <category>javascript</category>
      <param name="templateName" type="string"/>
      <param name="attach" type="boolean"/>
      <param name="templateData" type="string"/>
      <description>Render a document with a given template and converts it to PDF.</description>
      <script><![CDATA[
        function run(input, params) {
          var blob = TemplateProcessor.Render(input, {
            'templateName': params.templateName,
            'attach': params.attach || false,
            'templateData': params.templateData || null
          });
          return Blob.RunConverter(blob, {'converter': 'any2pdf'});
        }
      ]]></script>
    </scriptedOperation>

  </extension>

</component>